home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / Converse / Source / Preferences.m < prev    next >
Text File  |  1995-12-19  |  6KB  |  243 lines

  1. //** Craig Laurent
  2. #import <defaults/defaults.h>        //** for NXDefaultsVector
  3. #import <string.h>
  4. #import "Preferences.h"
  5.  
  6. #define DEFAULTSOWNER "ConverseLaurent"
  7.  
  8. #define NUMDEFAULTS 9
  9. #define DEFAULTALERTAUDIO "AlertAudio"
  10. #define DEFAULTALERTSOUND "AlertSound"
  11. #define DEFAULTALERTICON "AlertIcon"
  12. #define DEFAULTALERTWINDOW "AlertWindow"
  13. #define DEFAULTALERTAPPLICATION "AlertApplication"
  14. #define DEFAULTDISCLOSEID "DiscloseID"
  15. #define DEFAULTDISCLOSENAME "DiscloseName"
  16. #define DEFAULTDISCLOSEMACHINE "DiscloseMachine"
  17. #define DEFAULTADDRESSFILE "AddressFile"
  18.  
  19. @implementation Preferences
  20.  
  21. - init
  22. {
  23.     const NXDefaultsVector    defaults = {
  24.         {DEFAULTALERTAUDIO, "YES"}
  25.         ,{DEFAULTALERTSOUND, "Avon.snd"}
  26.         ,{DEFAULTALERTICON, "YES"}
  27.         ,{DEFAULTALERTWINDOW, "YES"}
  28.         ,{DEFAULTALERTAPPLICATION, "NO"}
  29.         ,{DEFAULTDISCLOSEID, "YES"}
  30.         ,{DEFAULTDISCLOSENAME, "YES"}
  31.         ,{DEFAULTDISCLOSEMACHINE, "YES"}
  32.         ,{DEFAULTDISCLOSEMACHINE, "YES"}
  33.         ,{DEFAULTADDRESSFILE, ""}
  34.         ,{NULL}
  35.     };
  36.  
  37.     if (self = [super init]) {
  38.         NXRegisterDefaults(DEFAULTSOWNER, defaults);
  39.         soundFile = nil;
  40.         [self loadPreferences];
  41.         return self;
  42.     }
  43.     return nil;
  44. }
  45.  
  46. - (void)dealloc
  47. {
  48.     if ([self soundFile])
  49.         [self setSoundFile:nil];
  50.     [super dealloc];
  51. }
  52.  
  53. //****************************************
  54. //** instance methods
  55. - (BOOL)alertAudio
  56. {    return alertAudio; }
  57. - (void)setAlertAudio:(BOOL)audio
  58. {
  59.     alertAudio = audio;
  60. }
  61.  
  62. - (BOOL)alertIcon
  63. {    return alertIcon; }
  64. - (void)setAlertIcon:(BOOL)icon
  65. {
  66.     alertIcon = icon;
  67. }
  68.  
  69. - (BOOL)alertWindow
  70. {    return alertWindow; }
  71. - (void)setAlertWindow:(BOOL)window
  72. {
  73.     alertWindow = window;
  74. }
  75.  
  76. - (BOOL)alertApplication
  77. {    return alertApplication; }
  78. - (void)setAlertApplication:(BOOL)application
  79. {
  80.     alertApplication = application;
  81. }
  82.  
  83. - (BOOL)discloseID
  84. {    return discloseID; }
  85. - (void)setDiscloseID:(BOOL)dID
  86. {
  87.     discloseID = dID;
  88. }
  89.  
  90. - (BOOL)discloseName
  91. {    return discloseName; }
  92. - (void)setDiscloseName:(BOOL)dName
  93. {
  94.     discloseName = dName;
  95. }
  96.  
  97. - (BOOL)discloseMachine
  98. {    return discloseMachine; }
  99. - (void)setDiscloseMachine:(BOOL)dMachine
  100. {
  101.     discloseMachine = dMachine;
  102. }
  103.  
  104. - (NSString*)soundFile
  105. {    return soundFile;    }
  106. - (void)setSoundFile:(NSString*)file
  107. {
  108.     [soundFile autorelease];
  109.     soundFile = [file retain];
  110. }
  111.  
  112. - (NSString*)addressFile
  113. {    return addressFile;    }
  114. - (void)setAddressFile:(NSString*)file
  115. {
  116.     [addressFile autorelease];
  117.     addressFile = [file retain];
  118. }
  119.  
  120.  
  121. //****************************************
  122. /* loadPreferences - load preference information */
  123. - (void)loadPreferences
  124. {
  125.     const char    *tempDefault;
  126.  
  127.     //** load preference information from DEFAULTS.
  128.     //**  database takes precedence over NXRegisterDefaults
  129.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTALERTAUDIO)))
  130.         [self setAlertAudio:YES];
  131.     else
  132.         [self setAlertAudio:NO];
  133.  
  134.     tempDefault = NXGetDefaultValue(DEFAULTSOWNER, DEFAULTALERTSOUND);
  135.     if (0 == strcmp(tempDefault, ""))
  136.         [self setSoundFile:nil];
  137.     else
  138.         [self setSoundFile:[NSString stringWithCString:tempDefault]];
  139.  
  140.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTALERTICON)))
  141.         [self setAlertIcon:YES];
  142.     else
  143.         [self setAlertIcon:NO];
  144.  
  145.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTALERTWINDOW)))
  146.         [self setAlertWindow:YES];
  147.     else
  148.         [self setAlertWindow:NO];
  149.  
  150.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTALERTAPPLICATION)))
  151.         [self setAlertApplication:YES];
  152.     else
  153.         [self setAlertApplication:NO];
  154.  
  155.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTDISCLOSEID)))
  156.         [self setDiscloseID:YES];
  157.     else
  158.         [self setDiscloseID:NO];
  159.  
  160.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTDISCLOSENAME)))
  161.         [self setDiscloseName:YES];
  162.     else
  163.         [self setDiscloseName:NO];
  164.  
  165.     if (0 == strcmp("YES", NXGetDefaultValue(DEFAULTSOWNER, DEFAULTDISCLOSEMACHINE)))
  166.         [self setDiscloseMachine:YES];
  167.     else
  168.         [self setDiscloseMachine:NO];
  169.  
  170.     tempDefault = NXGetDefaultValue(DEFAULTSOWNER, DEFAULTADDRESSFILE);
  171.     if (0 == strcmp(tempDefault, ""))
  172.         [self setAddressFile:nil];
  173.     else
  174.         [self setAddressFile:[NSString stringWithCString:tempDefault]];
  175. }
  176.  
  177.  
  178. //**********
  179. /* savePreferences - save preference information */
  180. - (void)savePreferences
  181. {
  182.     NXDefaultsVector newDefaults = {
  183.         {DEFAULTALERTAUDIO, "YES"}
  184.         ,{DEFAULTALERTSOUND, "Avon.snd"}
  185.         ,{DEFAULTALERTICON, "YES"}
  186.         ,{DEFAULTALERTWINDOW, "YES"}
  187.         ,{DEFAULTALERTAPPLICATION, "NO"}
  188.         ,{DEFAULTDISCLOSEID, "YES"}
  189.         ,{DEFAULTDISCLOSENAME, "YES"}
  190.         ,{DEFAULTDISCLOSEMACHINE, "YES"}
  191.         ,{DEFAULTADDRESSFILE, ""}
  192.         ,{NULL}
  193.     };
  194.     int    defaultsWritten = 0;
  195.  
  196.     if ([self alertAudio])
  197.         newDefaults[0].value = "YES";
  198.     else
  199.         newDefaults[0].value = "NO";
  200.  
  201.     newDefaults[1].value = (char*)[[self soundFile] cString];
  202.  
  203.     if ([self alertIcon])
  204.         newDefaults[2].value = "YES";
  205.     else
  206.         newDefaults[2].value = "NO";
  207.  
  208.     if ([self alertWindow])
  209.         newDefaults[3].value = "YES";
  210.     else
  211.         newDefaults[3].value = "NO";
  212.  
  213.     if ([self alertApplication])
  214.         newDefaults[4].value = "YES";
  215.     else
  216.         newDefaults[4].value = "NO";
  217.  
  218.     if ([self discloseID])
  219.         newDefaults[5].value = "YES";
  220.     else
  221.         newDefaults[5].value = "NO";
  222.  
  223.     if ([self discloseName])
  224.         newDefaults[6].value = "YES";
  225.     else
  226.         newDefaults[6].value = "NO";
  227.  
  228.     if ([self discloseMachine])
  229.         newDefaults[7].value = "YES";
  230.     else
  231.         newDefaults[7].value = "NO";
  232.  
  233.     newDefaults[8].value = (char*)[[self addressFile] cString];
  234.  
  235.     //** write preference information to defaults.
  236.     defaultsWritten = NXWriteDefaults(DEFAULTSOWNER, newDefaults);
  237.     if (!(NUMDEFAULTS == defaultsWritten))
  238.         NXRunAlertPanel("Preferences Alert", "Unable to write all preferences %d / %d.", NULL, NULL, NULL, defaultsWritten, NUMDEFAULTS);
  239. }
  240.  
  241.  
  242. @end
  243.